# -*- coding: UTF-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

import datetime  # For datetime objects
import os.path  # To manage paths
import sys  # To find out the script name (in argv[0])

# Import the backtrader platform
import backtrader as bt

import MySQLDataFeed as mdf
import SimpleMySqlClass as smc
import talib as talib
import numpy as np
import akshare as ak
import pandas as pd
import json


# 获取数据库链接
def get_mysql_conn():
    conn = smc.SimpleMySqlClass("127.0.0.1", "stocks", "haojg", "haojg")
    return conn


def del_table_data(table_name, conn):
    del_sql = "delete from %s"
    rs = conn.execute(del_sql % table_name)
    print("删除%s表数据%d条" % (table_name, rs))
    return rs


def drop_table(table_name, conn):
    drop_sql = "drop table if exists %s"
    rs = conn.execute(drop_sql % table_name)
    print("删除%s表%d" % (table_name, rs))
    return rs


def list_table(conn):
    all_tables = conn.list_tables()
    return all_tables


def run_clear_mysql_data():
    # 获取链接
    conn = get_mysql_conn()
    table_name = "t_trade_data_000001"
    del_table_data(table_name, conn)
    drop_table(table_name, conn)
    tables = list_table(conn)
    print(tables)
    # 关闭连接
    conn.close()


if __name__ == "__main__":
    print("开始清数")
    run_clear_mysql_data()
